package mapper

import (
	"goproject/src/model"
	"gorm.io/gorm"
	"strconv"
)

// 获取预约单
func GetAllOrders(pageSize string, page string, db *gorm.DB) []model.DesOrder {
	var desOrder []model.DesOrder
	size, _ := strconv.Atoi(pageSize)
	pageInt, _ := strconv.Atoi(page)
	var offset int = (pageInt - 1) * size
	db.Limit(size).Offset(offset).Find(&desOrder)
	return desOrder
}

func DeleteOrderById(db *gorm.DB, id string) {
	db.Delete(&model.DesOrder{}, id)
}

func QueryOrderTotals(db *gorm.DB) int64 {
	// 执行原生 SQL Raw为原生sql
	var num int64
	db.Raw("SELECT count(1) FROM des_order").Count(&num)
	return num
}

func GetAllOrdersFilter(db *gorm.DB, name string) []model.DesOrder {
	// 执行原生 SQL Raw为原生sql，列能自动映射到实体中
	var orders []model.DesOrder
	db.Raw("SELECT *  FROM des_order where order_num=?", name).Scan(&orders)
	return orders
}
